﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

namespace MyTestProject {

    public class TestBlender {
        [Fact]
        public void TestConstructor () {
            var blender = new Blender ();

            Assert.Equal (0x00000000u, blender.BlendColor);
            Assert.Equal (Blender.Add, blender.BlendFunction[Blender.SrcColor]);
            Assert.Equal (Blender.Add, blender.BlendFunction[Blender.SrcAlpha]);
            Assert.Equal (Blender.One, blender.BlendFactor[Blender.SrcColor]);
            Assert.Equal (Blender.One, blender.BlendFactor[Blender.SrcAlpha]);
            Assert.Equal (Blender.Zero, blender.BlendFactor[Blender.DstColor]);
            Assert.Equal (Blender.Zero, blender.BlendFactor[Blender.DstAlpha]);
        }

        [Fact]
        public void TestSetBlenderColor () {
            var bln = new Blender ();
            bln.BlendColor = 0x87654321;

            Assert.Equal (0x87654321u, bln.BlendColor);
        }

        [Fact]
        public void TestGetBlendFunction () {
            var bln = new Blender ();
            bln.SetBlendFunctions (Blender.Subtract, Blender.ReverseSubtract);

            Assert.Equal (Blender.Subtract, bln.BlendFunction[Blender.SrcColor]);
            Assert.Equal (Blender.ReverseSubtract, bln.BlendFunction[Blender.SrcAlpha]);
        }

        [Fact]
        public void TestSetBlendFactor () {
            var bln = new Blender ();
            bln.SetBlendFactors (Blender.SrcAlphaSaturate, Blender.OneMinusConstantAlpha, Blender.One, Blender.ConstantAlpha);

            Assert.Equal (Blender.SrcAlphaSaturate     , bln.BlendFactor[Blender.SrcColor]);
            Assert.Equal (Blender.OneMinusConstantAlpha, bln.BlendFactor[Blender.SrcAlpha]);
            Assert.Equal (Blender.One                  , bln.BlendFactor[Blender.DstColor]);
            Assert.Equal (Blender.ConstantAlpha        , bln.BlendFactor[Blender.DstAlpha]);
        }

        [Fact]
        public void TestDuplicate () {
            var bln = new Blender ();
            bln.BlendColor = 0x87654321;
            bln.SetBlendFunctions (Blender.Subtract, Blender.ReverseSubtract);
            bln.SetBlendFactors (Blender.SrcAlphaSaturate, Blender.OneMinusConstantAlpha, Blender.One, Blender.ConstantAlpha);
            bln.UserID = 100;

            var dup = (Blender)bln.Duplicate ();

            Assert.Equal (bln.BlendColor, dup.BlendColor);
            Assert.Equal (bln.BlendFunction[Blender.SrcColor], dup.BlendFunction[Blender.SrcColor]);
            Assert.Equal (bln.BlendFunction[Blender.SrcAlpha], dup.BlendFunction[Blender.SrcAlpha]);
            Assert.Equal (bln.BlendFactor[Blender.SrcColor], dup.BlendFactor[Blender.SrcColor]);
            Assert.Equal (bln.BlendFactor[Blender.SrcAlpha], dup.BlendFactor[Blender.SrcAlpha]);
            Assert.Equal (bln.BlendFactor[Blender.DstColor], dup.BlendFactor[Blender.DstColor]);
            Assert.Equal (bln.BlendFactor[Blender.DstAlpha], dup.BlendFactor[Blender.DstAlpha]);
            Assert.Equal (bln.UserID, dup.UserID);
        }

    }
}
